angular.module('Controller')

.controller('QgyActiveDetailCtrl', ($scope,NgTableParams,wfAlert,menuManage,$localStorage,commonUtil,commonConstant,$rootScope,$uibModal,$http) ->
    $scope.type = $rootScope.pageType
    $scope.data=$rootScope.pageParams
    $scope.paramList=[]
    $scope.needVerifyList=commonConstant.needVerifyList()
    loadData=()->
        $http.get('/activity/'+$scope.data.id)
        .success((resp)->
            if resp.code==0
                $scope.detail=resp.message
                $scope.paramList=resp.message.params
#                createQrcode()
                console.log(resp.message)
        )
    $scope.activeTypeList=[]
    loadActiveType=()->
        $http.get('/dictionary?dicIndex=3&page=0&size=999')
        .success((resp)->
            if resp.code==0
                $scope.activeTypeList=resp.message.content
        )
    loadActiveType()
    createQrcode=()->
        options={
            text:"{activeId:"+$scope.detail.id+"}"
        }
        $('#active-qrcode').qrcode("{activeId:"+$scope.detail.id+"}")
    loadData()
    $scope.costTypeList=commonConstant.enterFeeTypeList()
    $scope.tableData=[]
    $scope.tableParams = new NgTableParams(
            {page: 1, count: commonConstant.pageTableCount},
            {
                counts: [5, 10, 20],
                getData: ($defer, params)->
                    $scope.doQuery($defer,params)
                    return ;
            }
    )
    $scope.doQuery=($defer, params)->
        requestData={
            page: params.page() - 1,
            size: params.count(),
            eventId:$scope.data.id
        }
        getParam=commonUtil.transferGetParam(requestData)
        $http.get('/activity/enterUsers'+getParam)
        .success (resp)->
            if resp.code==0
                $scope.tableData=resp.message.content
                params.total(resp.message.totalElements)
                $defer.resolve($scope.tableData)
            else
                console.log(resp.message)
        .error (err)->
            console.log(err)
    $scope.showAddress=()->
        showMapModal('view',{name:$scope.detail.address})
    $scope.viewPerson=(item)->
        ''
    showMapModal=(type,data)->
        $scope.modal = $uibModal.open({
            animation: true,
            appendTo: $("#modalContent:eq(0)"),
            controller: 'WfMapModalCtrl',
            templateUrl: 'templates/main/map-modal/map-modal.html',
            resolve: {
                items:  ()->{type:type,data: data}
            }
        })
        $scope.modal.result.then((modalData)->
            $scope.data.address=modalData.name if modalData and modalData.name
        )
)